<?php

session_start();

if(file_exists("install/install.php"))
{
    header ("location: install/install.php");
}

// Include i file necessari
include('inc/config.inc.php');
include('inc/template.inc.php');
include('inc/db.inc.php');

//Variabili
if(isset($_GET['login']))
{
    $login = $_GET['login'];
} else {
    $login = 0;
}
// Risultati del login
$login_result = '';
switch ($login)
{
    case 1:
        $login_result = '<b class="glyphicon glyphicon-warning-sign"></b> Nome utente o Password errati.';
    break;
    case 2:
        $login_result = '<b class="glyphicon glyphicon-warning-sign"></b> Account inattivo, seguire il link nella mail inviata all\'email dichiarata all\'iscrizione';
    break;
    case 3:
        $login_result = '<b class="glyphicon glyphicon-warning-sign"></b> Inserire username e password.';
    break;
}

// Recupera il numero di presenti dal Database
$query = "SELECT COUNT(*) AS user_online FROM users WHERE user_lasttime > (NOW() - INTERVAL 2 MINUTE)";
if($results = $db -> query($query)) 
{
    $row = $results -> fetch_assoc();
	$online = $row['user_online'];
}

// Recupera il numero di gilde.
$query = "SELECT COUNT(*) AS game_guilds FROM guilds";
if($results = $db->query($query))
{
    $row = $results -> fetch_assoc();
        $guilds = $row['game_guilds'];
}

// Recupera il numero di razze.
$query = "SELECT COUNT(*) AS game_races FROM races";
if($results = $db -> query($query))
{
    $row = $results -> fetch_assoc();
        $races = $row['game_races'];
}

/*// Recupera le news
$query2 = "SELECT * FROM news ORDER BY news_date DESC LIMIT 0,10";
if($results2 = $db -> query($query2))
{
    $content = '';
    while($row2 = $results2 -> fetch_assoc())
    {
        $author_id = $row2['news_author'];
        
        $query = "SELECT user_name FROM users WHERE user_id = $author_id";
	if($results = $db -> query($query))
        {
            $row = $results->fetch_assoc();
            $content .= '<h2>'.htmlentities($row['user_name']).'</h2><strong>'.$row2['news_date'].'</strong> <p>'.bbtext($row2['news_content']).'</p>';
	}
    }
}*/

// Lista delle tag speciali
$tags = array(
    'temp_title' => $g_name, 'temp_online' => $online, 
    /*'temp_content' => $content,*/ 'temp_guilds' => $guilds, 'temp_races' => $races, 
    'temp_loginresult' => $login_result
 );

// Carica il template e formatta le tag speciali
$temp = new template('style/index.template.html');
$temp -> replace($tags);

// Visualizza l'output
echo $temp -> show();

?>